<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>网络货运平台省运管数据控制台</title>
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="小镖人、社区、网络货运">
    <meta name="description" content="小镖人、社区、网络货运">
    <link rel="stylesheet" href="../../../xbr_layui_extend/layui-v2.6.8/css/layui.css">
    <style>
        .layui-input-block {
            margin-left: 0;
            margin-right: 10px
        }
    </style>
</head>
<body>
<div class="layui-fluid" style="padding: 15px;">
    <form class="layui-form" action="" lay-filter="form-post" id="userForm" method="post">
        <div class="layui-row">
            <div class="layui-col-xs4">
                <div class="layui-form-item" id="payAcc">
                    <div class="layui-input-block">
                        <select id="bankcard" name="bankcardId" lay-filter="bankcard"></select>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" id="date" name="queryDate" placeholder="请选择交易日期">
                    </div>
                </div>
            </div>
            <div class="layui-col-xs3">
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <div class="layui-input-block">
                            <select name="bsnCode" >
                                <option value="">全部</option>
                                <option value="0000">基础结算明细</option>
                                <option value="4047">单笔代扣</option>
                                <option value="4032">橙e收款</option>
                                <option value="FEEM">手续费扣费</option>
                                <option value="KHKF">跨行快付</option>
                                <option value="404701">代发代扣</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs2">
                <div class="layui-form-item" style="text-align: center">
                    <a class="layui-btn" lay-submit="" lay-filter="post-btn">查询</a>
                </div>
            </div>
        </div>
    </form>
    <!--表格部分-->
    <table class="layui-hide" id="accTable" lay-filter="accTable"></table>
    <!--隐藏模板 -->
    <script type="text/html" id="bar">
        <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="download">添加下载任务</a>
    </script>
</div>

<script src="../../../xbr_layui_extend/layui-v2.6.8/layui.js"></script>
<script>
    layui.extend({
        admin: '/platform/xbr_layui_extend/admin' //集成路径
    }).use(["admin", 'form'], function () {
        const $ = layui.$, form = layui.form, admin = layui.admin, table = layui.table, laydate = layui.laydate;
        let bankcardList = [];
        //函数栈
        queryPayBankCard(function (cardList) {
            bankcardList = cardList;
            bindOptions($("#bankcard"), '请选择交易账户', cardList, (item) => item.id, function (item) {
                const endNo = item['bankAccNo'].substring(item['bankAccNo'].length - 4, item['bankAccNo'].length);
                return item['bankName'] + "(****" + endNo + ')';
            });
            form.render(null, 'form-post');
            refTable([]);
        });

        //加载table
        function refTable(itemList) {
            table.render({
                elem: '#accTable',
                height: 450,
                limit: 999,
                cols: [[ //标题栏
                    {title: '文件名称', minWidth: 100, templet: (d) => nullTxt(d["fileName"])},
                    {title: '文件路径', templet: (d) => nullTxt(d["filePath"])},
                    {title: '随机密码', minWidth: 100, templet: (d) => nullTxt(d["randomPwd"])},
                    {title: '签名值', templet: (d) => nullTxt(d["signData"])},
                    {title: 'SHA-1摘要', templet: (d) => nullTxt(d["hashData"])},
                    {fixed: 'right', title: '操作', toolbar: '#bar', width: 130}
                ]],
                data: itemList,
            });
        }

        //监听行工具事件
        table.on('tool(accTable)', function(obj){
            const data = obj.data;
            if (obj.event==='download'){
                admin.req({
                    url: "/platform/pab/reqDownloadTradeDetails",
                    data: {fileName: data.fileName, randomPwd: data.randomPwd},
                    done: function (res) {
                        layer.msg("已添加到下载任务！", {offset: 'auto', icon: 1,time:1000});
                    }
                });
            }
        });

        //上传完毕 提交表单
        form.render(null, 'form-post');
        form.on('submit(post-btn)', function (data) {
            const bankcardId = data.field.bankcardId;
            let filter = bankcardList.filter(item => item.id === bankcardId);
            const bankcard = filter.length > 0 ? filter[0] : null;
            const outAcctNo = bankcard['bankAccNo'];
            const queryDate = data.field.queryDate;
            const bsnCode = data.field.bsnCode;
            loadDataList(queryDate, outAcctNo, bsnCode);
            return false;
        });

        //读取数据
        const loadDataList = (queryDate, bankAccNo, bsnCode) => {
            admin.req({
                url: "/platform/pab/reqTradeDetailsDownloadList",
                data: {queryDate: queryDate, bankAccountNo: bankAccNo, bsnCode: bsnCode},
                done: function (res) {
                    if (res.data == null) return;
                    if (res.data["itemList"] == null) res.data.itemList = [];
                    refTable(res.data.itemList);
                }
            });
        };

        //日期时间选择器
        laydate.render({
            format: 'yyyy-MM-dd',
            elem: '#date',
        });

        function nullTxt(value) {
            if (value == null || value === "") return "无数据";
            return value;
        }

        //绑定下拉选项
        function bindOptions(jqElm, hint, dataList, valueBack, labelBack) {
            jqElm.empty();
            jqElm.append('<option value="">' + hint + '</option>');
            for (let item of dataList) {
                jqElm.append('<option value="' + valueBack(item) + '">' + labelBack(item) + '</option>');
            }
        }

        //获取付款人（平台）银行卡列表
        function queryPayBankCard(callback) {
            admin.req({
                url: "/platform/bank/getBankCardList",
                data: {"bankShortName": "SPABANK"},
                done: function (res) {
                    callback(res.data);
                }
            });
        }


    });
</script>
</body>
</html>